package com.siwei.mes.entity.experiment.cement;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

/**
 * @Description: 水泥-安定性
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class CementAdx {
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "雷氏法信息")
    private CementAdx.Lsf lsf = new CementAdx.Lsf();

    @ApiModelProperty(value = "试饼法信息")
    private CementAdx.Sbf sbf = new CementAdx.Sbf();

    @Data
    @Accessors(chain = true)
    @ApiModel("雷氏法信息")
    public static class Lsf {
        @ApiModelProperty(value = "煎煮A")
        private String jza = "";
        @ApiModelProperty(value = "煎煮C")
        private String jzc = "";
        @ApiModelProperty(value = "增加距离C-A")
        private String zjjl = "";
        @ApiModelProperty(value = "煎煮A1")
        private String jza1 = "";
        @ApiModelProperty(value = "煎煮C1")
        private String jzc1 = "";
        @ApiModelProperty(value = "增加距离C-A1")
        private String zjjl1 = "";
        @ApiModelProperty(value = "C-A平均值")//1
        private String pjz = "";
        @ApiModelProperty(value = "结论")//1
        private String jl = "";
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("试饼法信息")
    public static class Sbf {
        @ApiModelProperty(value = "有无纹裂")
        private String ywlw = "";
        @ApiModelProperty(value = "是否弯曲")
        private String sfwq = "";
        @ApiModelProperty(value = "结论")//1
        private String jl = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        CementAdx entity = new CementAdx();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, CementAdx.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, CementAdx.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        CementAdx entity = JsonUtils.getObject(objJson, CementAdx.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        CementAdx.Lsf lsf = entity.getLsf();
        CementAdx.Sbf sbf = entity.getSbf();
        if (lsf == null && sbf == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isNotBlank(sbf.getJl()) && !"null".equals(sbf.getJl())) {
            return null;
        } else {
            if (StringUtils.isBlank(lsf.getPjz()) || "null".equals(lsf.getPjz())) {
                return "存在必检项(" + name + ")未检测，请先检测！";
            }
            /*if (StringUtils.isBlank(lsf.getJl()) || "null".equals(lsf.getJl())) {
                return "存在必检项(" + name + ")未检测，请先检测！";
            }*/
        }
        return null;
    }
}
